#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void swap(char* a, char* b)
{
    char c = *a;
    *a = *b;
    *b = c;
}
int main()
{
    char map[80][80] = { 0 };
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%s", &map[i][j]);
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = m - 1; j > 0; j--)
        {
            if (map[j][i] == '0' && map[j - 1][i] != '1')
            {
                if (map[j][i] == '0' && map[j - 1][i] == '0')
                {
                    ;
                }
                else swap(&map[j][i], &map[j-1][i]);
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            printf("%c ", map[i][j]);
        }
        printf("\n");
    }
    return 0;
}